class SocketIoWebPlugin {

    constructor(socketIoConfig) {
        this.key=socketIoConfig.key;
        this.clientId=socketIoConfig.clientId;
        this.path=socketIoConfig.path;
        this.host=socketIoConfig.host;
        this.socket=null;
    }



    async install(app,args){
        const callback=args.callback;
        M.cache.linkJs("https://cdn.bootcss.com/socket.io/2.1.1/socket.io.js");
        for (let i=0;i<10;i++){
            await M.delayMs(10);
            if(window.io){
                break
            }
        }
        var socket = window.io(this.host+ '/?uid='+this.clientId,{path:`/socket.io`});
        socket.on('event',async function (msg) {
            callback(msg);
        });
        MIO.socketEmit=(event,params)=> socket.emit(event, {...params,uid:this.clientId});
    }

}

export default  SocketIoWebPlugin;

